//
//  LiveCourse.m
//  Courses
//
//  Created by xxx on 15/1/6.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "LiveCourse.h"
#import "RequestBody.h"

@implementation LiveCourse

- (id)initWithJsonDict:(NSDictionary *)jsonDict
{
    if (self = [super initWithJsonDict:jsonDict])
    {
        self.liveId = jsonDict[@"liveId"];
        self.beginTime = jsonDict[@"beginTime"];
        self.name = jsonDict[@"name"];
        self.vodId = jsonDict[@"vodId"];
        self.liveState = jsonDict[@"liveState"];
    }
    return self;
}

+ (NSArray *)getLiveCoursesWithDateIndex:(NSInteger)dateOffset
{
    NSMutableArray *liveCourses = [[NSMutableArray alloc] init];
    
    Request *request = [Request requestWithName:@"get_lives"];
    
    request.body[@"dateIdex"] = [NSString stringWithFormat:@"%ld", dateOffset];
    
    Response *res = [request response];
    if (!res.result)
    {
        return [liveCourses copy];
    }
    
    for (id courseJson in res.content[@"lives"])
    {
        LiveCourse *course = [[self alloc] initWithJsonDict:courseJson];
        [liveCourses addObject:course];
    }
    return [liveCourses copy];
}

@end
